﻿/*****************************************************************//**
 * @file    FITKGraphObjectSurface.h
 * @brief   Mesh surface data exchange class.
 * 
 * @sa
 * FITKSetSurfPolyProvider
 *  
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-04-01
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTSURFACE_H__
#define __FITKGRAPHOBJECTSURFACE_H__

#include "FITKGraphObjectHighlightBase.h"

#include "FITKVTKGraphAdaptorAPI.h"

// Forward declaration
class QVariant;

class vtkUnstructuredGrid;
class vtkIdList;
class vtkSelectionNode;
class vtkSelection;
class vtkExtractSelection;
class vtkIdTypeArray;

class FITKGraphActor;

namespace Interface
{
    class FITKAbaMeshPartVTK;
    class FITKAbstractAssInstance;
    class FITKMeshSurface;
    class FITKMeshSurfaceElement;
    class FITKMeshSurfaceNode;
    struct AbaEleSurface;
}

namespace AbaqusData
{
    class FITKAbaqusPart;
}

/**
 * @brief   The type of surface for vtk.
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-05-14
 */
enum SurfaceDataType
{
    CellSurface = 0,
    PointSurface = 1
};

namespace Exchange
{
    /**
     * @brief   Mesh highlight graph object class for 'surface'.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-04-10
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectSurface : public FITKGraphObjectHighlightBase
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectSurface, FITKGraphObjectHighlightBase);
        FITKCLASS(Exchange, FITKGraphObjectSurface);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data
         * @param   surface: The input mesh element or node surface data need to be exchanged
         * @param   details: Nothing [default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-10
         */
        FITKGraphObjectSurface(AbaqusData::FITKDataCase* caseData, Interface::FITKMeshSurface* surface, QVariant details = QVariant());

        /**
         * @brief   Destructor.[virtual]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-10
         */
        virtual ~FITKGraphObjectSurface();

        /**
         * @brief   Update the visibility of surface.
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-14
         */
        void update(bool forceUpdate = false) override;

        /**
         * @brief   Update the visibility with data object's visibility.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-14
         */
        void updateVisibility() override;

    private:
        /**
         * @brief   Initialize the pointers.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-18
         */
        void init();

        /**
         * @brief   Generate the poly data for the surface.
         * @param   surface: The surface data object
         * @return  Is OK
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-18
         */
        bool generatePolyData(Interface::FITKMeshSurface* surface);

        /**
         * @brief   Generate the graph actor with the surface.
         * @param   assemblyData: The assembly data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-18
         */
        void generateGraph();

    private:
        /**
         * @brief   The type of surface.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-14
         */
        SurfaceDataType m_type = CellSurface;

        /**
         * @brief   The original surface poly data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-14
         */
        vtkUnstructuredGrid* m_gridData{ nullptr };

        /**
         * @brief   The graph actor for the surface.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-14
         */
        FITKGraphActor* m_fActor{ nullptr };

        /**
         * @brief   The selection node for extract mesh grid.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-14
         */
        vtkSelectionNode* m_selectNode{ nullptr };

        /**
         * @brief   The selection for vtkSelectionNode.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-14
         */
        vtkSelection* m_section{ nullptr };

        /**
         * @brief   The mesh grid extractor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-14
         */
        vtkExtractSelection* m_extractSelection{ nullptr };

        /**
         * @brief   The indice array of extract id.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-05-14
         */
        vtkIdTypeArray* m_idArray{ nullptr };

        /**
         * @brief   If this set is belonged to an assembly-instance, this id will be not -1.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-04-12
         */
        int m_instanceId = -1;

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTSURFACE_H__
